import { openAccurateTab } from '@src/util/platform';
import { ConnectorBizTypeEnum } from '@src/modules/connector/model/enum';
import { PageRoutesTypeEnum } from 'pub-bbx-global/pageType/dist/enum/PageRoutesEnum';
import platform from "@src/platform";
import { t } from "@src/locales";

// 连接器跳转对应业务的新建页面
export const connectorJumpToCreate = (data: any) => {
  const { toBizType, toBizTypeId } = data;
  if (!toBizType) return;

  // 新建合同
  if (toBizType === ConnectorBizTypeEnum.Contract) {
    openAccurateTab({
      type: PageRoutesTypeEnum.PageContractCreate,
      params: `contractTemplateId=${toBizTypeId}`,
    });
  }
  // 新建工单
  if (toBizType === ConnectorBizTypeEnum.Task) {
    openAccurateTab({
      type: PageRoutesTypeEnum.PageCreateTask,
      params: `defaultTypeId=${toBizTypeId}`,
    });
  }
  // 新建事件
  if (toBizType === ConnectorBizTypeEnum.Event) {
    openAccurateTab(
      {
        type: PageRoutesTypeEnum.PageEditEvent,
        params: `defaultTypeId=${toBizTypeId}`,
      }
    )
  }
  // 新建客户
  if (toBizType === ConnectorBizTypeEnum.Customer) {
    openAccurateTab(
      {
        type: PageRoutesTypeEnum.PageCreateCustomer,
      }
    )
  }
  // 新建产品
  if (toBizType === ConnectorBizTypeEnum.Product) {
    openAccurateTab(
      {
        type: PageRoutesTypeEnum.PageCreateProduct,
      }
    )
  }

  // 新建PAAS
  if (toBizType === ConnectorBizTypeEnum.Paas) {
    const { toBizTypeName } = data;
    const fromId = window?.frameElement?.getAttribute('id')
    platform.openTab({
      id: `create_view_${toBizTypeId}`,
      url: `/paas/#/template/edit?formId=${toBizTypeId}&fromSource=connectControl`,
      title: t('common.base.createModule', {data1: toBizTypeName}),
      fromId
    } as any)
  }
};
